﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autofac;

using Otonomos.Utils.Serialization;

namespace Test.Otonomos.Utils
{
    public class TestContainer
    {
        ContainerBuilder mBuilder;
        IContainer mContainer;

        public TestContainer()
        {
            mBuilder = new ContainerBuilder();
        }

        public TestContainer With<TImplementation>()
        {
            mBuilder.RegisterType<TImplementation>().AsImplementedInterfaces();
            return this;
        }

        public TestContainer With<TImplementation, TInterface>()
        {
            mBuilder.RegisterType<TImplementation>().As<TInterface>();
            return this;
        }

        public void Initialize()
        {
            mBuilder.RegisterType<JsonSerializer>().AsImplementedInterfaces();
            mContainer = mBuilder.Build();
        }

        public T Resolve<T>()
        {
            return mContainer.Resolve<T>();
        }
    }
}
